//package vipcard.meichehui.config;
//
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
//import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
//import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
//
//@Configuration
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        http
//            .authorizeRequests()
//                .antMatchers("/","index.html",  "/login").permitAll() // 允许所有人访问首页和登录页面
//                .anyRequest().authenticated() // 其他请求需要身份验证
//                .and()
//            .formLogin()
//                .loginPage("/index.html") // 指定登录页面
//                .successHandler(new SimpleUrlAuthenticationSuccessHandler("/AllMembers.html")) // 登录成功后跳转到首页
//                .failureHandler(new SimpleUrlAuthenticationFailureHandler("/index.html?error=true")) // 登录失败后跳转到登录页面
//                .permitAll()
//                .and()
//            .logout()
//                .logoutSuccessHandler(logoutSuccessHandler())
//                .permitAll()
//                .and()
//            .sessionManagement()
//                .invalidSessionUrl("/index.html") // session无效时跳转到登录页面
//                .maximumSessions(1); // 每个用户最多只能有一个有效会话
//    }
//
//    private LogoutSuccessHandler logoutSuccessHandler() {
//        return (request, response, authentication) -> response.sendRedirect("/AllMembers.html");
//    }
//}
